package ${basePackage}.service.impl;

import ${basePackage}.dao.${modelNameUpperCamel}Mapper;
import ${basePackage}.model.${modelNameUpperCamel};
import ${basePackage}.model.${modelNameUpperCamel}Example;
import ${basePackage}.service.${modelNameUpperCamel}Service;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import com.mass.core.utils.*;
import org.springframework.util.ObjectUtils;
/**
* Created by ${author} on ${date}.
*/
@Service
@Transactional
public class ${modelNameUpperCamel}ServiceImpl implements ${modelNameUpperCamel}Service {

    @Autowired
    private ${modelNameUpperCamel}Mapper ${modelNameLowerCamel}Mapper;

    @Transactional
    @Override
    public int insert(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        return ${modelNameLowerCamel}Mapper.insert(${modelNameLowerCamel});
    }

    @Transactional
    @Override
    public int delete(Long ${modelNameLowerCamel}Id) {
        return ${modelNameLowerCamel}Mapper.deleteByPrimaryKey(${modelNameLowerCamel}Id);
    }

    @Transactional
    @Override
    public int update(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        return ${modelNameLowerCamel}Mapper.updateByPrimaryKeySelective(${modelNameLowerCamel});
    }

    @Override
    public ${modelNameUpperCamel} selectById(Long ${modelNameLowerCamel}Id) {
        return ${modelNameLowerCamel}Mapper.selectByPrimaryKey(${modelNameLowerCamel}Id);
    }

    @Override
    public AjaxResponse selectPage(${modelNameUpperCamel} ${modelNameLowerCamel},Integer page ,Integer limit) {
        ${modelNameUpperCamel}Example example = new ${modelNameUpperCamel}Example();
		if(!ObjectUtils.isEmpty(page)){
			example.setPageIndex((page-1)*limit);
			example.setPageSize(limit);
		}
        ${modelNameUpperCamel}Example.Criteria criteria = example.createCriteria();
		
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Mapper.selectByExample(example);
		Long count = ${modelNameLowerCamel}Mapper.countByExample(example);
        return AjaxResponse.success("ok", list, count,page);
    }
}
